import { getMenu, postMenu, getMenuByID, deleteMenuByID,  } from "@/api/ApiRequest" 

export default {
  data() {
    return {
      /// relateList

      /// table
      columns: [
        {
          title: '记录id',//记录id
          dataIndex: 'id',
          key: 'id',
          sort: 'up',
          align: 'center',
          width: 100,
          showTime: false,
        },
        {
          title: '菜单名称',//菜单名称
          dataIndex: 'title',
          key: 'title',
          sort: 'up',
          align: 'left',
          width: 100,
          showTime: false,
        },
        {
          title: '菜单路径',//菜单路径
          dataIndex: 'path',
          key: 'path',
          sort: 'up',
          align: 'left',
          width: 100,
          showTime: false,
        },
        {
          title: '菜单图标',//菜单图标
          dataIndex: 'icon',
          key: 'icon',
          sort: 'up',
          align: 'left',
          width: 100,
          showTime: false,
        },
        {
          title: '菜单不可见',//菜单不可见
          dataIndex: 'inVisible',
          key: 'inVisible',
          sort: 'up',
          align: 'left',
          width: 100,
          showTime: false,
        },
        {
          title: '创建于',//创建于
          dataIndex: 'createAt',
          key: 'createAt',
          sort: 'up',
          align: 'center',
          width: 100,
          showTime: true,
        },
        {
          title: '更新于',//更新于
          dataIndex: 'updateAt',
          key: 'updateAt',
          sort: 'up',
          align: 'center',
          width: 100,
          showTime: true,
        },
        {
          title: '删除于',//删除于
          dataIndex: 'deleteAt',
          key: 'deleteAt',
          sort: 'up',
          align: 'center',
          width: 100,
          showTime: true,
        },

        {
          title: '操作',
          scopedSlots: {
            customRender: 'action',
          },
        },
      ],

      /// 搜索内容
      searchList: [
        {
          name: 'title', //菜单名称 
          title: '菜单名称',
          type: 'text', // text, number, numberRange, select, date, datetime, dateRange
          decorator: [
            'title',
            {
              rules: [
                { required: 0, message: '菜单名称 为必填项' },
              ],
            },
          ],
          sort: 'up',
          align: 'left',
          width: 100,
          showTime: false,
        },
        {
          name: 'path', //菜单路径 
          title: '菜单路径',
          type: 'text', // text, number, numberRange, select, date, datetime, dateRange
          decorator: [
            'path',
            {
              rules: [
                { required: 0, message: '菜单路径 为必填项' },
              ],
            },
          ],
          sort: 'up',
          align: 'left',
          width: 100,
          showTime: false,
        },
        {
          name: 'icon', //菜单图标 
          title: '菜单图标',
          type: 'text', // text, number, numberRange, select, date, datetime, dateRange
          decorator: [
            'icon',
            {
              rules: [
                { required: 0, message: '菜单图标 为必填项' },
              ],
            },
          ],
          sort: 'up',
          align: 'left',
          width: 100,
          showTime: false,
        },
        {
          name: 'inVisible', //菜单不可见 
          title: '菜单不可见',
          type: 'text', // text, number, numberRange, select, date, datetime, dateRange
          decorator: [
            'inVisible',
            {
              rules: [
                { required: 0, message: '菜单不可见 为必填项' },
              ],
            },
          ],
          sort: 'up',
          align: 'left',
          width: 100,
          showTime: false,
        },
        {
          name: 'createAt', //创建于 
          title: '创建于',
          type: 'date', // text, number, numberRange, select, date, datetime, dateRange
          decorator: [
            'createAt',
            {
              rules: [
                { required: 0, message: '创建于 为必填项' },
              ],
            },
          ],
          sort: 'up',
          align: 'center',
          width: 100,
          showTime: true,
        },
        {
          name: 'updateAt', //更新于 
          title: '更新于',
          type: 'date', // text, number, numberRange, select, date, datetime, dateRange
          decorator: [
            'updateAt',
            {
              rules: [
                { required: 0, message: '更新于 为必填项' },
              ],
            },
          ],
          sort: 'up',
          align: 'center',
          width: 100,
          showTime: true,
        },
      ],

      /// 表单信息列表
      formList: [
        {
          name: 'title', //菜单名称 
          title: '菜单名称',
          type: 'text', // text, number, numberRange, select, date, datetime, dateRange
          decorator: [
            'title',
            {
              rules: [
                { required: 0, message: '菜单名称 为必填项' },
              ],
            },
          ],
          sort: 'up',
          align: 'left',
          width: 100,
          showTime: false,
        },
        {
          name: 'path', //菜单路径 
          title: '菜单路径',
          type: 'text', // text, number, numberRange, select, date, datetime, dateRange
          decorator: [
            'path',
            {
              rules: [
                { required: 0, message: '菜单路径 为必填项' },
              ],
            },
          ],
          sort: 'up',
          align: 'left',
          width: 100,
          showTime: false,
        },
        {
          name: 'icon', //菜单图标 
          title: '菜单图标',
          type: 'text', // text, number, numberRange, select, date, datetime, dateRange
          decorator: [
            'icon',
            {
              rules: [
                { required: 0, message: '菜单图标 为必填项' },
              ],
            },
          ],
          sort: 'up',
          align: 'left',
          width: 100,
          showTime: false,
        },
        {
          name: 'inVisible', //菜单不可见 
          title: '菜单不可见',
          type: 'text', // text, number, numberRange, select, date, datetime, dateRange
          decorator: [
            'inVisible',
            {
              rules: [
                { required: 0, message: '菜单不可见 为必填项' },
              ],
            },
          ],
          sort: 'up',
          align: 'left',
          width: 100,
          showTime: false,
        },
      ],

      listRequest: getMenu,
      addRequest: postMenu,
      editRequest: postMenu,
      detailRequest: getMenuByID,
      deleteRequest: deleteMenuByID,
    };
  },
  methods: {
    async init() {
    },
    //===================== 处理请求参数
    // 列表请求参数
    async handleListRequestParams(params) {
      this.log("handleListRequestParams", params);
      return params;
    },
    // 新增或者修改保存参数
    async handleSaveRequestParams(params) {
      this.log("handleSaveRequestParams", params);
      return params;
    },
    // 请求详情接口参数
    async handleDetailRequestParams(params) {
      this.log("handleDetailRequestParams", params);
      return params;
    },
    // 删除列表参数
    async handleDeleteRequestParams(params) {
      this.log("handleDeleteRequestParams", params);
      return params;
    },
    // 处理列表返回数据
    // async handleListData(data) {
    //  this.log("handleListData", data);
    //  return data;
    // },
    //===================== search
    // 准备搜索回调
    onWillSearch(params) {
      this.log("onWillSearch", params);
    },
    // 准备搜索回调
    onWillSearchReqeust(params, pagination) {
      this.log("onWillSearchReqeust", params, pagination);
    },
    // 完成搜索回调
    onDidSearch() {
      this.log("onDidSearch");
    },

    //===================== 列表
    // 准备调用列表接口
    onWillGetList() {
      this.log("onWillGetList");
    },
    // 即将开始请求列表接口
    onWillGetListRequest(params) {
      this.log("onWillGetListRequest", params);
    },
    // 列表请求成功
    onGetListSuccess(data) {
      this.log("onGetListSuccess", data);
    },
    // 列表请求失败
    onGetListError(error) {
      this.log("onGetListError", error);
    },

    //===================== 新增
    // 准备新增
    onWillAdd() {
      this.log("onWillAdd");
    },
    // 新增成功
    onAddSuccess(data) {
      this.log("onAddSuccess", data);
    },
    // 新增失败
    onAddError(error) {
      this.log("onAddError", error);
    },

    //===================== 更新
    // 准备更新
    onWillEdit(data) {
      this.log("onWillEdit", data);
    },
    // 更新成功
    onEditSuccess(data) {
      this.log("onEditSuccess", data);
    },
    // 更新失败
    onEditError(error) {
      this.log("onEditError", error);
    },

    // 准备调用新增或者修改接口
    onWillSaveReqeust(params) {
      this.log("onWillSaveReqeust", params);
    },

    //===================== 删除
    // 准备删除
    onWillDelete(id) {
      this.log("onWillDelete", id);
    },
    // 即将开始请求删除接口
    onWillDeleteReqeust(params) {
      this.log("onWillDeleteReqeust", params);
    },
    // 删除成功
    onDeleteSuccess(data) {
      this.log("onDeleteSuccess", data);
    },
    // 删除失败
    onDeleteError(error) {
      this.log("onDeleteError", error);
    },

    //===================== 其他
    // form表单前缀内容点击
    onFormPrefixClick(error) {
      this.log("onFormPrefixClick", error);
    },
    // form表单后缀内容点击
    onFormSuffixClick(error) {
      this.log("onFormSuffixClick", error);
    },
    log(title, msg) {
      console.log(`[Menu->${title}]`, msg ?? "");
    }
  },
};
